﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using QLHD.BLL;

namespace QLHD.DAL
{
    public class CTXuatKho_DB
    {
        public static DataTable ReportTCXuat_Tho()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spReportTCXuat_Tho", con);
                con.Open();
                SqlCommand command = new SqlCommand("spReportTCXuat_Tho", con);
                command.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
 
        }
        public static DataTable ReportXuat_Tho()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spReportXuat_Tho", con);
                con.Open();
                SqlCommand command = new SqlCommand("spReportXuat_Tho", con);
                command.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        public static DataTable SelectAllXuat_Tho()
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spSelectAll_CTXuatNLTho", con);
                con.Open();
                SqlCommand command = new SqlCommand("spSelectAll_CTXuatNLTho", con);
                command.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                return dt;
            }
        }
        public static void InsertCTXuat_Tho(CTXuatKho newCTXuatTho)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spThemCT_XuatNL_Tho", con);
                con.Open();
                SqlCommand command = new SqlCommand("spThemCT_XuatNL_Tho", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaXuatNL", newCTXuatTho.MaXuatNL);
                command.Parameters.AddWithValue("@NgayThang", newCTXuatTho.Ngaythang);
                command.Parameters.AddWithValue("@MaNX", newCTXuatTho.Manx);
                command.Parameters.AddWithValue("@MaLo", newCTXuatTho.Malo);
                command.Parameters.AddWithValue("@MaNhom", newCTXuatTho.Manhom);
                command.Parameters.AddWithValue("@DienGiai", newCTXuatTho.Diengiai);
                command.Parameters.AddWithValue("@KL_Xuat", newCTXuatTho.Kl_xuat);
                command.Parameters.AddWithValue("@MaKho", newCTXuatTho.Makho);
                command.ExecuteNonQuery();

            }
        }
        public static void UpdateCTXuat_Tho(string oldMaXuatpNL, CTXuatKho newCTXuatTho)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spCapNhatCT_XuatNL_Tho", con);
                con.Open();
                SqlCommand command = new SqlCommand("spCapNhatCT_XuatNL_Tho", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaXuatNL", oldMaXuatpNL);
                command.Parameters.AddWithValue("@NgayThang", newCTXuatTho.Ngaythang);
                command.Parameters.AddWithValue("@MaNX", newCTXuatTho.Manx);
                command.Parameters.AddWithValue("@MaLo", newCTXuatTho.Malo);
                command.Parameters.AddWithValue("@MaNhom", newCTXuatTho.Manhom);
                command.Parameters.AddWithValue("@DienGiai", newCTXuatTho.Diengiai);
                command.Parameters.AddWithValue("@KL_Xuat", newCTXuatTho.Kl_xuat);
                command.Parameters.AddWithValue("@MaKho", newCTXuatTho.Makho);
                command.ExecuteNonQuery();
            }
        }
        public static void DeleteCTXuat_Tho(string maXuatNL)
        {
            using (SqlConnection con = Connection.GetConnection())
            {
                SqlDataAdapter da = new SqlDataAdapter("spXoaCT_XuatNL_Tho", con);
                con.Open();
                SqlCommand command = new SqlCommand("spXoaCT_XuatNL_Tho", con);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@MaXuatNL", maXuatNL);
                command.ExecuteNonQuery();

            }
        }
    }
}
